import GameEvent from "../../Commons/GameEvent";
import { getZeroTime } from "../../GlobalFunction";
import ConfigManager from "../../Managers/ConfigManager";
import SaveManager from "../../Managers/SaveManager";
import TipsTxtManager from "../../Managers/TipsTxtManager";
import UIManager from "../../Managers/UIManager";
import SigninEntity from "./SigninEntity";

export enum SigninEvent {
    SIGNIN_EVENT = "signin_event"
}

export default class SigninManager implements IModelManager {

    private static _single: SigninManager = null;
    public static get single(): SigninManager {
        if (SigninManager._single == null) {
            SigninManager._single = new SigninManager();
        }
        return SigninManager._single;
    }

    initConfig(): void {

    }

    getSigninEntity(day: number): SigninEntity {
        var userdata = SaveManager.single.userdata;

        for (const iterator of userdata.signinArr) {
            if (iterator.day == day) {
                return iterator;
            }
        }
        return null;
    }

    requestSignin(day: number) {
        var userdata = SaveManager.single.userdata;
        // if (userdata.isSignin) {
        //     UIManager.single.showTips("今日已签到");
        //     return;
        // }
        var arr = ConfigManager.single.signinConfig;
        userdata.diamond += arr[day].amount;
        userdata.signinArr[day].isReceive = true;
        userdata.isSignin = true;
        userdata.signinTime = getZeroTime();
        UIManager.single.showTips("签到成功，钻石+" + arr[day].amount + "。");
        SaveManager.single.saveData();

        GameEvent.eventNode.emit(SigninEvent.SIGNIN_EVENT);
        GameEvent.eventNode.emit(GameEvent.CURRENCYUPDATA_EVENT);

    }
}
